import 'package:flutter/material.dart';
import '../model/post.dart';
import 'view_demo.dart';
import 'listViewDemo.dart';

class SliverDemo extends StatelessWidget{

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: CustomScrollView(
        slivers:<Widget>[
        SliverAppBar(
          //title:Text('nihao'),
          floating:true,
          expandedHeight: 170,
          flexibleSpace: FlexibleSpaceBar(
            background: Image.network(
              'http://3.0.169.87/pxmart_upload/image/15535640628607891.png',
              fit: BoxFit.cover,
            ),
            title:Text(
              'NING HAO'.toUpperCase(),
              style: TextStyle(
                 fontSize:15.0,
                 letterSpacing:3,
                 fontWeight:FontWeight.w400
              ),
            )
          ),

        ),

        SliverSafeArea( 
          sliver: SliverPadding(
            padding: EdgeInsets.all(10),
            sliver: SliverGaridDemo()
           )
         )
        ],
      ),
    );
  }
}

class SliverListDemo extends StatelessWidget{
 @override
  Widget build(BuildContext context) {
    return SliverList(delegate: SliverChildBuilderDelegate(
            (BuildContext context,int index){
                   return Padding(
                     padding: EdgeInsets.only(bottom:32.0),
                     child: Material(
                       elevation:10,
                       borderRadius:BorderRadius.circular(12),
                       shadowColor: Colors.grey.withOpacity(0.5),
                       child: Stack(
                         children:<Widget>[
                           AspectRatio(
                             aspectRatio: 16/9,
                             child: Image.network(
                               posts[index].imageUrl,
                               fit: BoxFit.cover,
                             ),
                           ),
                           Positioned(
                             top: 10,
                             left: 10,
                             child: Column(
                               crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Text(
                                    posts[index].title,
                                    style: TextStyle(fontWeight:FontWeight.bold,fontSize: 32,color: Colors.white),
                                  ),
                                   Text(
                                    posts[index].author,
                                    style: TextStyle(fontWeight:FontWeight.normal,fontSize: 32,color: Colors.white),
                                  ),
                                  ],
                           ))
                          
                         ]
                       ),
                     ),
                     
                     );
                },
              childCount:posts.length,
    ));
  }
}


class SliverGaridDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  SliverGrid(
            delegate: SliverChildBuilderDelegate(
                (BuildContext context,int index){
                   return Container(
                     child: Image.network(
                       posts[index].imageUrl,
                       fit: BoxFit.cover,
                       ),
                   );
                   
                },
                childCount:posts.length, 
              ),
             gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
               crossAxisCount: 2,
               crossAxisSpacing: 10,
               mainAxisSpacing: 10,
               childAspectRatio: 1.5
               )
          
             );
  }
}